/*
 *  Copyright 2012 SerGenis. All rights reserved.
 */
package com.sergenis.swing.plaf;

import java.awt.*;
import java.util.Formatter;
import javax.swing.JComponent;
import javax.swing.JProgressBar;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicGraphicsUtils;
import javax.swing.plaf.basic.BasicProgressBarUI;

/**
 *
 * @author SerGenis
 */
public class GenisProgressBarUI
    extends BasicProgressBarUI {

    private Rectangle innards;
    private Rectangle box;

    public static ComponentUI createUI(JComponent c) {
	return new GenisProgressBarUI();
    }

    @Override
    protected void paintString(Graphics g, int x, int y, int width, int height, int amountFull, Insets b) {
	synchronized ( progressBar ) {
	    String srt = progressBar.getString();
	    Formatter formatter = new Formatter();
	    if (srt != null && !srt.equals("")) {
		srt = formatter.format("%s [%.1f]", srt,
		    progressBar.getPercentComplete() * 100).toString();
	    } else {
		srt = formatter.format("%.1f",
		    progressBar.getPercentComplete() * 100).toString();
	    }
	    System.out.println(srt);
	    progressBar.setString(srt);
	    super.paintString(g, x, y, width, height, amountFull, b);
	}
    }
}
